package com.atguigu.chap05;

import java.util.Random;
import java.util.concurrent.TimeUnit;

public class JoinDemo {

    /**
     * main方法也是一个进程，在这里是主进程，即上锁的同学
     */
    public static void main(String[] args) throws InterruptedException {

        Runnable runnable = () -> {
            try {
                TimeUnit.SECONDS.sleep(new Random().nextInt(5));
                System.out.println(Thread.currentThread().getName() + " 同学出门了");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        };


        Thread t1 = new Thread(runnable);
        t1.start();

        Thread t2 = new Thread(runnable);
        t2.start();

        Thread t3 = new Thread(runnable);
        t3.start();

        Thread t4 = new Thread(runnable);
        t4.start();

        Thread t5 = new Thread(runnable);
        t5.start();

        Thread t6 = new Thread(runnable);
        t6.start();

        //子线程并入主线程
        t1.join();
        t2.join();
        t3.join();
        t4.join();
        t5.join();
        t6.join();

        System.out.println("值班同学锁门了");
    }
}